package org.su.webadapter.bind;

import org.apache.commons.lang.StringUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;


public class TimeEditor extends AbstractParameterEditor {
	private final DateFormat dateFormat;

	public TimeEditor(DateFormat dateFormat) {
		this.dateFormat = dateFormat;
	}

	public TimeEditor() {
		dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		dateFormat.setLenient(false);
	}

	public Object parseText(String text) {
		Object result = null;
		if (StringUtils.isNotBlank(text)) {
				try {
					result = new java.sql.Time(this.dateFormat.parse(text).getTime());
				} catch (ParseException e) {
					throw new ParamBindException(e);
				}
			
		}
		return result;
	}
}
